home *** CD-ROM | disk | FTP | other *** search
- property pWhichKey, pChosenKey, pGettingKey
- global gKeys
-
- on getPropertyDescriptionList me
- list = [:]
- addProp(list, #pWhichKey, [#comment: "Which Key?", #format: #symbol, #default: #left, #range: [#left, #right, #gas, #brake]])
- return list
- end
-
- on beginSprite me
- keyData = VOID
- if voidp(gKeys) then
- gKeys = [:]
- end if
- if voidp(keyData) then
- keyData = [:]
- addProp(keyData, #left, [#text: "Left Arrow", #key: 123])
- addProp(keyData, #right, [#text: "Right Arrow", #key: 124])
- addProp(keyData, #gas, [#text: "Up Arrow", #key: 126])
- addProp(keyData, #brake, [#text: "Down Arrow", #key: 125])
- end if
- chooseKey(me, keyData[pWhichKey].key, keyData[pWhichKey].text)
- end
-
- on chooseKey me, keyCode, whichKey
- keyData = VOID
- if voidp(keyData) then
- keyData = [:]
- addProp(keyData, #left, [#text: "Left Arrow", #key: 123])
- addProp(keyData, #right, [#text: "Right Arrow", #key: 124])
- addProp(keyData, #gas, [#text: "Up Arrow", #key: 126])
- addProp(keyData, #brake, [#text: "Down Arrow", #key: 125])
- end if
- oldKeyCode = keyData[pWhichKey].key
- oldWhichKey = keyData[pWhichKey].text
- case pWhichKey of
- #left:
- gKeys[#left] = keyCode
- #right:
- gKeys[#right] = keyCode
- #gas:
- gKeys[#gas] = keyCode
- #brake:
- gKeys[#brake] = keyCode
- end case
- case keyCode of
- 123:
- text = "Left Arrow"
- 124:
- text = "Right Arrow"
- 125:
- text = "Down Arrow"
- 126:
- text = "Up Arrow"
- 49:
- text = "Space"
- 48:
- text = "Tab"
- 36:
- text = "Enter"
- otherwise:
- text = whichKey
- end case
- keyData[pWhichKey].text = text
- keyData[pWhichKey].key = keyCode
- sprite(me.spriteNum).member.text = text
- pGettingKey = 0
- sendAllSprites(#newKeyChosen, pWhichKey, keyCode, text, oldKeyCode, oldWhichKey)
- end
-
- on newKeyChosen me, fromWhichKey, newKeyCode, newWhichKey, oldKeyCode, oldWhichKey
- if fromWhichKey <> pWhichKey then
- if gKeys[pWhichKey] = newKeyCode then
- chooseKey(me, oldKeyCode, oldWhichKey)
- end if
- end if
- end
-
- on getTheKey me
- pGettingKey = 1
- sprite(me.spriteNum).member.text = EMPTY
- end
-
- on keyWasPressed me, keyCode, whichKey
- if pGettingKey then
- chooseKey(me, keyCode, whichKey)
- end if
- end
-